package com.behome.common.core.domain;

import com.behome.common.core.domain.entity.SysRegion;
import com.fasterxml.jackson.annotation.JsonInclude;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * Treeselect树结构实体类
 * 
 * @author behome
 */
public class TreeSelectByRegion implements Serializable
{
    private static final long serialVersionUID = 1L;

    /** 节点ID */
    private String id;

    /** 节点名称 */
    private String label;

    /** 子节点 */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<TreeSelectByRegion> children;

    public TreeSelectByRegion()
    {

    }

    public TreeSelectByRegion(SysRegion region)
    {
        this.id = region.getRegionId();
        this.label = region.getName();
        this.children =  Optional.ofNullable(region.getChildren()).orElse(new ArrayList<>())
                .stream()
                .filter(Objects::nonNull)
                .map(TreeSelectByRegion::new)
                .collect(Collectors.toList());
    }


    public String getId()
    {
        return id;
    }

    public void setId(String id)
    {
        this.id = id;
    }

    public String getLabel()
    {
        return label;
    }

    public void setLabel(String label)
    {
        this.label = label;
    }

    public List<TreeSelectByRegion> getChildren()
    {
        return children;
    }

    public void setChildren(List<TreeSelectByRegion> children)
    {
        this.children = children;
    }
}
